package DAY1209.Demo3;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:LiRegin
 * @Date: 2019/12/9 16:56:16
 */
public class Test {
    public static void main(String[] args) throws DocumentException {
        ArrayList<Student> list=new ArrayList<Student>();
        SAXReader reader = new SAXReader();
        Document dom = reader.read(new File("C:\\XML\\src\\DAY1209\\Demo3\\student.xml"));
        Element root = dom.getRootElement();
        List<Element> servletList = root.elements("student");
        for (Element servlet : servletList) {
            List<Element> elements = servlet.elements();
            list.add(new Student(servlet.attributeValue("stuNo"),elements.get(0).getText(),Integer.parseInt(elements.get(1).getText()),
                    elements.get(2).getText(),Integer.parseInt(elements.get(3).getText())));
        }
        System.out.println(list.toString());
    }
}
